
// background.htmlからのポストを受け取る
chrome.extension.onRequest.addListener(
	function(request, sender, sendResponse) {
		console.log("content.js start:");
		console.log(request);
		// console.log(sender);
		// console.log(sendResponse);
		doWork(request);
		sendResponse({ret:1});	// レスポンスも返せる
	}
);

/**
 *  メイン
 *
 **/
function doWork(event){
		var users = [];
		users.push('<table border="1" id="att"><caption>' + event.title + 
			'<span class="sub">出欠表（参加者、キャンセル待ちのみ）</span>' +
			'</caption>' + 
			'<thead><tr><th></th><th></th><th>NAME</th><th>Twitter</th><th>MEMO</th></tr></thead><tbody>'
		);
		for(var i = 0; i < event.users.length ; i++){
			console.log(event.users[i].nickname);
			if (event.users[i].twitter_img){
			}else{
				event.users[i].twitter_img = 'http://atnd.org/images/icon/default_latent.png';
				event.users[i].twitter_id = '';
			}
			users.push(
				'<tr class="st' + event.users[i].status + '">' + 
				'<td class="no">' + (i+1) + '</td>' +
				'<td class="icon"><img src="' + event.users[i].twitter_img + '" width="24" height="24" /></td>' + 
				'<td class="name"><a href="http://atnd.org/users/show/' + event.users[i].user_id + '" target="_blank">' + event.users[i].nickname + '</a></td>' + 
				'<td class="twna"><a href="http://twitter.com/' + event.users[i].twitter_id + '" target="_blank">' + event.users[i].twitter_id + '</a></td>' + 
				'<td class="memo">&nbsp;</td>' +
				'</tr>'
			);
		}
		users.push('</tbody></table>');
		$('.notice').after(users.join(""));
}

